﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Xsl;
using System.Xml;
using System.IO;
using System.Xml.XPath;

namespace XslPad.Core.Managers
{
    public static class BasicXslTransformer
    {
        public static string Transform(string inputXml, string inputXsl)
        {
            string resultXML = string.Empty;
            //------------------------------------------------------------------------------------

            // Création du transformer
            XslCompiledTransform proc = new XslCompiledTransform();


            // Chargement du flux XML d'entrée
            using (StringReader sr = new StringReader(inputXsl))
            {
                using (XmlReader xr = XmlReader.Create(sr))
                {
                    proc.Load(xr);
                }
            }

            // Création du flux de sortie
            using (StringReader sr = new StringReader(inputXml))
            {
                using (XmlReader xr = XmlReader.Create(sr))
                {
                    using (StringWriter sw = new StringWriter())
                    {
                        proc.Transform(xr, null, sw);
                        resultXML = sw.ToString();
                    }
                }
            }


            //------------------------------------------------------------------------------------
            return resultXML;
        }
    }
}
